/* This file is part of the Pardus Economy Planner.

   The Pardus Economy Planner is free software: you can redistribute it
   and/or modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.

   The Pardus Economy Planner is distributed in the hope that it
   will be useful, but WITHOUT ANY WARRANTY; without even the implied
   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with the Pardus Economy Planner.  If not, see
   <http://www.gnu.org/licenses/>.
*/

// Constants

var User = { Username: "", Password: "", Verified: false };
var Server = { MaxServers: 0, MaxPricelists: 0 };
var Version = 2;
var ProtocolVersion = 1;
var CookieVersion = 1;

// Prototypes

var Global = {};
var Lib = {
  Object: {},
  Text: {},
  Time: {}
};
var Utility = {
  Commodities: {},
  Config: {},
  Debug: {},
  Map: {},
  Object: {},
  ObjectInfo: {},
  Pricelist: {},
  Sector: {},
  Server: {},
  Tile: {}
};
var Panels = {
  About: {},
  Commodities: {},
  Config: {},
  Help: {},
  Main: {},
  Pricelist: {},
  Settings: {}
};
var ExportModule = {}; // Singular, only one
var ImportModules = {}; // Plural, multiple for each 

Global.Sectors = []; // Saved sectors (not the displayed)
Global.CurrentSector = null;
Global.DisplayedSector = null; // Sector the user sees
Global.MapNames = []; // Built in Pardus maps

Global.Pricelists = []; // Saved pricelists (not the displayed)
Global.CurrentPricelist = [];
Global.DisplayedPricelist = null; // Pricelist the user sees

Global.CachedMaps = new Hash();

Global.CurrentTile = { cell: null, x: null, y: null, id: null, tile: null };

var RightClickMenu = $("RightClickMenu");
var LeftClickMenu = $("LeftClickMenu");

var EventSink = new Element("span");

function HideMenus()
{
  RightClickMenu.set("html", "");
  LeftClickMenu.set("html", "");
}

window.addEvent("load", function()
{
  $("mainBodyRegion").setStyle("display", "block");
  $("mainBodyRegion").fade("in");
  $("initCenterArea").fade("out");
});

var MainTabControl = new TabSwapper({
  rearrangeDOM: false,
  selectedClass: "NavOn",
  deselectedClass: "NavOff",
  tabs: $$("td[id$=TabLink]"),
  sections: $$("div[id$=Tab]"),
  smooth: false
});
MainTabControl.addEvent("active", HideMenus);

var PricelistTabControl = new TabSwapper({
  rearrangeDOM: false,
  selectedClass: "NavOn",
  deselectedClass: "NavOff",
  tabs: [$("PricelistMainSectionLink"), $("PricelistOverviewSectionLink")],
  sections: [$("PricelistMainSection"), $("PricelistOverviewSection")],
  smooth: false
});

var CommodityTabControl = new TabSwapper({
  rearrangeDOM: false,
  selectedClass: "NavOn",
  deselectedClass: "NavOff",
  tabs: [$("CommoditiesTick"), $("CommoditiesDay"), $("CommoditiesWeek")],
  sections: [new Element("div"), new Element("div"), new Element("div")],
  smooth: false
});